<script setup name="sparecollec">
import addForm from './addForm.vue'

// 表格加载状态
const loading = ref(false)

// 新增弹窗状态
const addIsShow = ref(false)

// title
const title = ref('新增')

//备件领用  表格数据
const TableData = ref([])

// 列表总数量
const total = ref(0)

// 表单
const ruleForm = reactive({})

// 查询条件
const SelectList = ref([
  { label: '备件领用单号', model: 'a', type: '输入框' },
  { label: '备件名称', model: 'a', type: '输入框' },
  { label: '单据状态', model: 'a', type: '下拉单选' }
])

// 查询条件
const query = reactive({
  pageNum: 1,
  pageSize: 10
})

// 添加 弹窗
const purchase = () => {
  title.value = '添加'
  addIsShow.value = true
}

// 关闭弹窗
const close = () => {
  addIsShow.value = false
}

// 条件查询
const selectSubmit = Obj => {
  for (let KEY in Obj) {
    query[KEY] = Obj[KEY]
  }
  getList()
}

// 获取列表
const getList = async () => {
  loading.value = true
  try {
    const res = await GetPrintingAPI(query)
    TableData.value = res.rows
    total.value = res.total
  } catch (error) {
  } finally {
    loading.value = false
  }
}
// getList()
</script>

<template>
  <div class="app-container">
    <!-- 查询条件组件 -->
    <SelectForm :SelectForm="SelectList" @selectSubmit="selectSubmit" />
    <el-card class="box-card">
      <div class="btnmp">
        <el-button type="primary" v-hasPermi="['spareadmin:admin:sparecollec:add']" @click="purchase">添加</el-button>
        <el-button
          type="primary"
          v-hasPermi="['spareadmin:admin:sparecollec:subexamine']"
          :disabled="delDisabled"
          @click="smallRollDia"
          >提交审核</el-button
        >
        <el-button
          type="primary"
          v-hasPermi="['spareadmin:admin:sparecollec:examine']"
          :disabled="delDisabled"
          @click="smallRollDia"
          >审核</el-button
        >
        <el-button
          type="primary"
          v-hasPermi="['spareadmin:admin:sparecollec:close']"
          :disabled="delDisabled"
          @click="smallRollDia"
          >关结</el-button
        >
        <el-button
          type="primary"
          v-hasPermi="['spareadmin:admin:sparecollec:remove']"
          :disabled="delDisabled"
          @click="smallRollDia"
          >删除</el-button
        >
        <el-button
          type="primary"
          v-hasPermi="['spareadmin:admin:sparecollec:outexamine']"
          :disabled="delDisabled"
          @click="smallRollDia"
          >撤销审核</el-button
        >
        <el-button
          type="primary"
          v-hasPermi="['spareadmin:admin:sparecollec:detail']"
          :disabled="delDisabled"
          @click="smallRollDia"
          >领用明细</el-button
        >
        <el-button
          type="primary"
          v-hasPermi="['spareadmin:admin:sparecollec:code']"
          :disabled="delDisabled"
          @click="smallRollDia"
          >扫码出库</el-button
        >
      </div>
      <el-table v-loading="loading" stripe border :data="TableData" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" fixed="left" />
        <el-table-column label="备件领用单号" prop="receiptNo" width="120" align="center" />
        <el-table-column label="单据状态" align="center" prop="wodStatus" width="90">
          <template #default="scope">
            <div>
              <p-tag bgc="#0663aa" text="待提交" v-if="scope.row.wodStatus == 1" />
              <p-tag bgc="#fabf3c" text="待审核" v-else-if="scope.row.wodStatus == 2" />
              <p-tag bgc="#ef8127" text="审核中" v-else-if="scope.row.wodStatus == 3" />
              <p-tag bgc="#fd0013" text="未通过" v-else-if="scope.row.wodStatus == 4" />
              <p-tag bgc="#69bc6d" text="待出库" v-else-if="scope.row.wodStatus == 5" />
              <p-tag bgc="#a094c9" text="出库中" v-else-if="scope.row.wodStatus == 6" />
              <p-tag bgc="#b6b6b6" text="已完成" v-else-if="scope.row.wodStatus == 7" />
              <p-tag bgc="#8f8f8f" text="已关结" v-else />
            </div>
          </template>
        </el-table-column>
        <el-table-column label="备件编码" prop="documentTypeDict" width="auto" align="center" />
        <el-table-column label="备件名称" prop="supplierName" width="auto" align="center" />
        <el-table-column label="退还标识" prop="quantityBatch" width="120" align="center" />
        <el-table-column label="计划领用数量" prop="printedQuantity" width="120" align="center" />
        <el-table-column label="已领用数量" prop="createBy" width="120" align="center" />
        <el-table-column label="领用部门" prop="createTime" width="120" align="center" />
        <el-table-column label="领用人" prop="printBy" width="auto" align="center" />
        <el-table-column label="开单人" prop="printBy" width="auto" align="center" />
        <el-table-column label="开单时间" prop="printBy" width="auto" align="center" />
        <el-table-column label="关结人" prop="printBy" width="auto" align="center" />
        <el-table-column label="关结时间" prop="printBy" width="auto" align="center" />
        <el-table-column label="操作" align="center" width="120" fixed="right" class-name="small-padding fixed-width">
          <template #default="scope">
            <div>
              <el-link
                type="primary"
                text="修改"
                v-hasPermi="['spareadmin:admin:sparecollec:edit']"
                @click="printFn(scope.row.productionId)"
              />
              <el-link
                type="primary"
                text="删除"
                v-hasPermi="['spareadmin:admin:sparecollec:remove']"
                @click="printFn(scope.row.productionId)"
              />
              <el-link
                type="primary"
                text="查看"
                v-hasPermi="['spareadmin:admin:sparecollec:query']"
                @click="printFn(scope.row.productionId)"
              />
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="query.pageNum"
        v-model:limit="query.pageSize"
        @pagination="getList"
      />
    </el-card>

    <p-XiaoheDialog :dialogVisible="addIsShow" :title="title" @close="close" width="50%">
      <template #body>
        <addForm />
        <Btn :loading="Btnloading" @close="close" @submit="title == '新增' ? addSub() : editSub()" />
      </template>
    </p-XiaoheDialog>
  </div>
</template>
<style lang="scss" scoped>
.btnmp {
  margin-bottom: 20px;
}
</style>
